package com.jwthhealth_pub.old.report.view.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jwthhealth_pub.R;
import com.jwthhealth_pub.old.report.model.resbody.SuggFoodRes;
import com.jwthhealth_pub.old.report.view.FoodSuggestActivity;

import java.util.List;

/**
 * Created by liuzhen on 2017/10/26.
 */

public class FoodSuggAdapter extends RecyclerView.Adapter {
    private final FoodSuggestActivity mActivity;
    private final List<SuggFoodRes.DataBean.SonBean> mData;

    public FoodSuggAdapter(FoodSuggestActivity foodSuggestActivity, List<SuggFoodRes.DataBean.SonBean> son) {
        this.mActivity = foodSuggestActivity;
        this.mData = son;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(View.inflate(mActivity, R.layout.item_key_value_food_sugg, null));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ViewHolder vh = (ViewHolder) holder;
        SuggFoodRes.DataBean.SonBean data = mData.get(vh.getAdapterPosition());
        vh.key.setText(data.getTitle());
        vh.value.setText(data.getValue());
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    private class ViewHolder extends RecyclerView.ViewHolder {

        private TextView key, value;

        public ViewHolder(View itemView) {
            super(itemView);
            key = itemView.findViewById(R.id.tv_key);
            value = itemView.findViewById(R.id.tv_value);
        }
    }
}
